package com.ibeeking.found.cop.b.rest.controller.v1;

import com.ibeeking.found.common.utils.UserUtils;
import com.ibeeking.found.cop.b.rest.service.IDataTalkGroupService;
import com.ibeeking.found.cop.b.rest.service.IDataTalkService;
import com.ibeeking.found.cop.service.common.vo.DataTalkFriendsViewVO;
import com.ibeeking.found.cop.service.common.vo.DataTalkVO;
import com.ibeeking.found.cop.service.common.vo.DataTalkViewVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName DataTalkController
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/b/dataTalk/v1")
public class DataTalkController {

    @Resource
    private IDataTalkService dataTalkServiceImpl;

    @Resource
    private IDataTalkGroupService dataTalkGroupServiceImpl;

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步获取会话同意情况")
    @PostMapping(value = "/syncFriendsAgree")
    public Integer syncDataTalkFriendsAgree() {
        Long tenantId = UserUtils.getTenantID();
        return dataTalkServiceImpl.syncBatchDataTalkFriendsAgreeFromWxCp(tenantId)?1:0;
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步获取会话内容存档开启成员列表")
    @PostMapping(value = "/syncFriendsPermit")
    public Integer syncDataTalkFriendsPermit() {
        Long tenantId = UserUtils.getTenantID();
        return dataTalkServiceImpl.syncBatchDataTalkFriendsPermitFromWxCp(tenantId)?1:0;
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步获取会话内容存档")
    @PostMapping(value = "/syncDataTalk")
    public Integer syncDataTalk() {
        Long tenantId = UserUtils.getTenantID();
        return dataTalkServiceImpl.syncBatchDataTalkFromWxCp(tenantId)?1:0;
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步获取群聊及成员")
    @PostMapping(value = "/syncDataTalkGroup")
    public Integer syncDataTalkGroup() {
        Long tenantId = UserUtils.getTenantID();
        return dataTalkGroupServiceImpl.syncBatchDataTalkGroupFromWxCp(tenantId)?1:0;
    }
    /*
    * type:1=内部好友；2=外部好友，3=群聊
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询员工好友列表")
    @PostMapping(value = "/queryFriendsList/{employeeCode}/{type}")
    public List<DataTalkFriendsViewVO> queryFriendsList(@PathVariable("employeeCode") String employeeCode, @PathVariable("type") Integer type) {
        return dataTalkServiceImpl.queryFriendsList(employeeCode, type);
    }
    /*
     * type:1=内部好友；2=外部好友，3=群聊
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询好友群列表")
    @PostMapping(value = "/queryGroupList/{code}")
    public List<DataTalkFriendsViewVO> queryGroupList(@PathVariable("code") String code) {
        return dataTalkServiceImpl.queryGroupList(code);
    }
    /*
     * type:1=内部好友；2=外部好友，3=群聊
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询聊天记录")
    @PostMapping(value = "/queryBySenderAndReceiverCode/{senderCode}/{receiverCode}/{type}")
    public DataTalkViewVO queryBySenderAndReceiverCode(@PathVariable("senderCode") String senderCode, @PathVariable("receiverCode") String receiverCode, @PathVariable("type") Integer type) {
        return dataTalkServiceImpl.queryBySenderAndReceiverCode(senderCode, receiverCode,type);
    }
    /*
     * type:1=内部好友；2=外部好友，3=群聊
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询聊天记录")
    @PostMapping(value = "/queryByGroupCode/{groupCode}")
    public DataTalkViewVO queryByGroupCode(@PathVariable("groupCode") String groupCode) {
        return dataTalkServiceImpl.queryByGroupCode(groupCode);
    }
    /*
     * test
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询聊天记录")
    @PostMapping(value = "/sendMsg/{type}")
    public Boolean sendMsg(@PathVariable("type") String type) {
        return dataTalkServiceImpl.sendMsg(type);
    }

}
